#!/usr/bin/env python
# -*- coding: utf-8 -*-
# --------------------------------------------------------
# Descripttion:
# version: 0.0.1
# Author: Wenwei Fu (2516800961@qq.com)
# FilePath: /fastapi_byd/app/api/routes/expert.py
# Create: 2021-01-04 16:37:40
# LastAuthor: Wenwei Fu
# lastTime: 2021-01-10 15:01:42
# --------------------------------------------------------

import os
import time
import uuid
import cv2
import numpy as np
import ast
import datetime
from typing import Optional, Any, List
from pydantic import BaseModel
from fastapi import APIRouter, Request, Body, Depends, HTTPException
from app.db.database import get_db
from app.api.routes.utils import coordinate_trans

router = APIRouter()

# 坐标转换
@router.post("/trans", name="坐标转换", dependencies=[Depends(get_db)])
async def coor_trans(
    direction: Optional[str] = 'north',
    coor_list: Optional[str] = '',
    request: Request=None
):
    coordinate_list = ast.literal_eval(coor_list)
    results = []
    trans_results = ''
    try:
        for coordinate in coordinate_list:
            if isinstance(coordinate, dict):
                # coor = list(map(int, list(coordinate.values()))) # list 中的项转 int
                coor = list(coordinate.values())
                trans_results = list(coordinate_trans(coor, direction))
            if isinstance(coordinate, list):
                trans_results = list(coordinate_trans(coordinate, direction))
            results.append(trans_results)
        print('results：', results)
        return {
            "code": 200,
            "message": "转换成功",
            "data": str(results)
        }
    except Exception as e:
        return {
            "code": 201,
            "message": str(e),
            "data": '失败'
        }


